package sbc.corso;

import corso.lang.CorsoData;
import corso.lang.CorsoDataException;
import corso.lang.CorsoShareable;

public class SensorSharable implements CorsoShareable {
	
	public String myId;
	public String Status;
	private static final String shareableStructName = new String ("MYSHAREABLESENSOR");
	
	public SensorSharable (String id, String status){
		this.myId=id;
		this.Status=status;
	}
	
	/** 
	 * Method which is called, if you read the structure from an oid 
	 * 
	 * @param data            CorsoData object from which the data is read 
	 * 
	 * @return                none 
	 * 
	 */ 
	public void read (CorsoData data) throws CorsoDataException { 
		StringBuffer structName = new StringBuffer (""); 
		 
		// first get the structure information ************************************ 
		int arity = data.getStructTag (structName); 
		if (arity != 2) { 
		  System.out.println ("arity of data is " + arity); 
		  throw new CorsoDataException (); 
		} 
		 
	    // here we also check the name of the structure *************************** 
	    if (!structName.toString ().equals (shareableStructName)) { 
	      throw new CorsoDataException (); 
	    } 
	 
	    // reading value from data ************************************************ 
		myId= data.getString (); 
		Status = data.getString();
	} 
	 
	/** 
	 * Method which is called, if you write the structure to an oid 
	 * 
	 * @param data            CorsoData object to which the data is written 
	 * 
	 * @return                none 
	 * 
	 */ 
	public void write (CorsoData data) throws CorsoDataException { 
	  	System.out.println("SensorSharable write begin");
		// first put the structure information ************************************ 
		data.putStructTag (shareableStructName, 2); 
	
		// write values to data *************************************************** 
		//data.putInt (i1); 
		data.putString (myId); 
		data.putString(Status);
	  	System.out.println("SensorSharable write end");
	} 
}